package LeetCode.linkedlist;

import java.util.HashSet;
import java.util.Set;

public class RingHasVaild {
    public static  ListNode crate(){
        ListNode head = new ListNode(0);
        ListNode node = head;
        for(int i=1;i<4;i++){
            node.next = new ListNode(i);
            node = node.next;

        }
        node.next = head;
        return head;
    }

    public static void show(ListNode head){
        ListNode node = head;
        while(node != null){
            System.out.println(node.var);
            node = node.next;
        }
    }

    public static boolean ifhas(ListNode head){
        ListNode node = head;
        Set<ListNode> listNodeSet = new HashSet<ListNode>();
        while(node != null){
            listNodeSet.add(node);
            node = node.next;
            if(listNodeSet.contains(node)){
                return  true;
            }
        }
        return  false;
    }

    public static void main(String[] args) {
        ListNode head = RingHasVaild.crate();
        System.out.println(RingHasVaild.ifhas(head));
    }
}
